<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="微社区,Q生活" name="keywords"/>
<meta content="微社区,Q生活" name="description"/>
<title>微社区|Q生活</title>
<link rel="stylesheet" href="${ctx }/static/css/Master.css"/>
<link rel="stylesheet" href="${ctx }/static/css/lq.datetimepick.css"/>
<link rel="stylesheet" href="${ctx }/static/css/jquery-labelauty.css"/>
<script src="${ctx }/static/js/jquery-1.9.0.min.js"></script>
<script src="${ctx }/static/js/simpletooltip.min.js"></script>
<script src="${ctx }/static/js/jquery-labelauty.js"></script>

<link href="${ctx}/static/css/validation.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="${ctx}/static/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.metadata.js"></script>
<script type="text/javascript" src="${ctx}/static/js/messages_cn.js"></script>

<link rel="stylesheet" href="${ctx}/static/plugins/JQuery zTree v3.5.15/css/zTreeStyle/zTreeStyle.css">
<script src="${ctx}/static/plugins/JQuery zTree v3.5.15/js/jquery.ztree.all-3.5.min.js"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<%-- 基础js,所有页面都需要引入此js,依赖layer.js --%>
<script src="${ctx}/static/js/common/base.js"></script>
<script src="${ctx}/static/js/common/util.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var msg = '此"类型编码"和"内容编码"的组合已存在';
	//异步验证是否符合唯一索引
    jQuery.validator.addMethod("checkUniqueIndex", function(value, element){
        var result = false;
        var id = $("#id").val();
        if(!id){
        	id=0;
        }
        var type = $("#type").val();
        var code = $("#code").val();
        // 任何一个为空时不验证
        if(!type || !type.trim() || !code){
        	$('label:contains('+msg+')').text('').hide();
        	return true;
        }
        // 设置同步
        $.ajaxSetup({
            async: false
        });
        $.get("${ctx}/dictionary/"+id+"/"+code+"/"+type+"/checkUniqueIndex", function(data){
        	if(typeof data == "string"){
        		if(data == "true"){
        			data = true;
        		}else{
        			data = false;
        		}
        	}
            result = data;
            
        });
        // 恢复异步
        $.ajaxSetup({
            async: true
        });
        if(result){
        	$('label:contains('+msg+')').text('').hide();
        }
        return result;
    }, msg);
});

function submit(){
	var form = $("#editForm");
	if(!form.valid()){
		return false;
	}
	
	$.ajax({    
	    //url:form.attr("action"),//可以不要   
	    data:form.serialize(),    
	    type:"post",    
	    cache:false,    
	    dataType:"json",
	    async:true, //默认为true 异步    
	    success:function(data) {    
	        top.layer.msg(data,{},function(){
	        	window.location="${ctx}/dictionary/list";   
            });
	     } 
	});
}
	
</script>
</head>

<body>

<section class="boxRight">
<form:form id="editForm" method="post" commandName="dictionary">
<form:hidden path="id"/>
		<div class="OrgTit">${op }</div>
		<div class="context">
			<div class="add_firstmenu">
				<dl>
					<dt>
						<span class="im">*</span>类型名称
					</dt>
					<dd>
						<form:input class="w1 required" path="typeName" maxlength="20"/>
					</dd>
				</dl>
				<dl>
					<dt><span class="im">*</span>类型编码</dt>
					<dd>
						<form:input class="w1 required checkUniqueIndex" path="type" maxlength="20"/>
					</dd>
				</dl>
				<dl>
					<dt><span class="im">*</span>内容</dt>
					<dd>
						<%--<form:input class="w1 required" path="content"/> #content样式错误覆盖--%>
						<input name="content" value="${dictionary.content }" class="w1 required" maxlength="20">
					</dd>
				</dl>
				<dl>
					<dt><span class="im">*</span>内容编码</dt>
					<dd>
						<form:input class="w1 utilInteger required digits checkUniqueIndex" path="code" maxlength="10"/>
					</dd>
				</dl>
				<dl>
					<dt>显示顺序</dt>
					<dd>
						<form:input class="w1 digits" path="showIndex" maxlength="5"/>
					</dd>
				</dl>
				
				
				<div class="combtn"><a href="javascript:void(0);" onclick="submit()">确定</a><a href="javascript:void(0);" onclick="history.back();">返回</a></div>
			</div>
		</div>
</form:form>
</section>

<%--树 --%>
<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
    <ul id="tree" class="ztree" ></ul>
</div>

</body>
</html>

